package com.ynu.yx.chatroleai.controller;



import com.ynu.yx.chatroleai.dto.UserDto;
import com.ynu.yx.chatroleai.dto.UserInfoDto;
import com.ynu.yx.chatroleai.dto.UserRegisterDto;
import com.ynu.yx.chatroleai.service.UserService;
import com.ynu.yx.chatroleai.utils.MsgOperation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@RestController
@RequestMapping("/user")
@Api(tags = "用户相关接口")
public class UserController {
    @Resource
    private UserService userService;


    @PostMapping("/register")
    @ApiOperation("用户注册（可选择系统图像作为头像）")
    public MsgOperation register(@RequestBody UserRegisterDto urdto) {
        return userService.registerUser(urdto);
    }

    @PostMapping("/login")
    @ApiOperation("用户登录")
    public MsgOperation login(String username, String password) {
        return userService.loginByUsername(username, password);
    }

    @PostMapping("/delete-uid")
    @ApiOperation("删除用户")
    public MsgOperation deleteUserUid(Long uid) {
        return userService.deleteUserByUid(uid);
    }

    @PutMapping("/delete-username")
    @ApiOperation("删除用户")
    public MsgOperation deleteUserUsername(String username) {
        return userService.deleteUserByUsername(username);
    }

    @GetMapping("/get-uid")
    @ApiOperation("通过uid查找用户")
    public UserDto getUserByUid(Long uid) {
        return userService.getUserByUid(uid);
    }

    @GetMapping("/get-username")
    @ApiOperation("通过username查找用户")
    public UserDto getUserByUsername(String username) {
        return userService.getUserByUsername(username);
    }

    @PutMapping("/ud-info-uid")
    @ApiOperation("通过uid修改用户基本信息")
    public MsgOperation udInfoUid(Long uid, @RequestBody UserInfoDto userInfoDto) {
        return userService.updateUserNormalInfoByUid(uid, userInfoDto);
    }

    @PutMapping("/ud-uname-uid")
    @ApiOperation("通过uid修改uname（用户名）")
    public MsgOperation udUname(Long uid, String newUsername) {
        return userService.updateUsernameByUid(uid, newUsername);
    }

    @PutMapping("/ud-pwd-uid")
    @ApiOperation("通过uid修改用户密码")
    public MsgOperation udPwd(Long uid, String pwd) {
        return userService.updatePwdByUid(uid, pwd);
    }

    @PutMapping("/ud-role-uid")
    @ApiOperation("通过uid修改用户角色")
    public MsgOperation udRole(Long uid, String role) {
        return userService.updateRoleByUid(uid, role);
    }


}


